/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.RRHH;

import gui.Ventas.ClienteAgregarJDialog;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author j.d
 */
public class CargaMasivaEmpleados extends javax.swing.JPanel {

    /**
     * Creates new form CargaMasivaEmpleados
     */
    public CargaMasivaEmpleados() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BtnExaminar = new javax.swing.JButton();
        TxtRuta = new javax.swing.JTextField();
        jProgressBar2 = new javax.swing.JProgressBar();

        setLayout(new java.awt.BorderLayout());

        BtnExaminar.setText("Examinar");
        BtnExaminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnExaminarActionPerformed(evt);
            }
        });
        add(BtnExaminar, java.awt.BorderLayout.PAGE_START);

        TxtRuta.setText("Ruta del archivo");
        add(TxtRuta, java.awt.BorderLayout.PAGE_END);
        add(jProgressBar2, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    private void BtnExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnExaminarActionPerformed
                // TODO add your handling code here:
        JFileChooser dlg = new JFileChooser();
        int option = dlg.showOpenDialog(this);
        String extension = new String();
        if(option == JFileChooser.APPROVE_OPTION){
            File archivo = dlg.getSelectedFile();
            
            String file = dlg.getSelectedFile().getPath();
            
            extension =file.substring(file.lastIndexOf("."));
            
            if(extension.equals(".csv")) {
                 
                try {
                
               JOptionPane.showMessageDialog(this, "Presione aceptar para iniciar la carga, esto puede tomar varios minutos");
                    
                    Controlador.Service.RRHH.GestionRRHH.agregarPersonalMasivo(file,jProgressBar2);
                    jProgressBar2.setValue(100);
                    JOptionPane.showMessageDialog(this, "La carga se realizo de manera correcta");
                } catch (Exception ex) {
                    
                   JOptionPane.showMessageDialog(this, "El archivo no está en el formato adecuado");
                }
            }else{
                    JOptionPane.showMessageDialog(this, "La extencion del Archivo debe ser CSV");
                            
                            
            }
        }
    }//GEN-LAST:event_BtnExaminarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnExaminar;
    private javax.swing.JTextField TxtRuta;
    private javax.swing.JProgressBar jProgressBar2;
    // End of variables declaration//GEN-END:variables
}
